#ifndef AI_SERVICE_IMPL_H
#define AI_SERVICE_IMPL_H

#include <map>
#include <string>
#include <mutex>
#include "ai_service_data_type.h"
#include "singleton.h"

#include "include/c_api/model_c.h"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/dnn.hpp"

namespace OHOS {
namespace AIS {

class AIServiceImpl : public Singleton<AIServiceImpl> {
public:
    int32_t Init(std::string& modelPath, int32_t* modelId);

    int32_t Process(const int32_t modelId, PicDesc& picDesc, std::string& picData, InferResult& result); 

    int32_t DeInit();

private:
    int32_t InitContext();
    
    int32_t CreateAndBuildModel(std::string& modelPath, int32_t* modelId);

    int32_t PreProcess(PicDesc& picDesc, std::string& picData, cv::Mat& blob);

    void PostProcess(OH_AI_ModelHandle& model, OH_AI_TensorHandleArray& outputs, InferResult& result, PicDesc& picDesc);

    int32_t Predict(OH_AI_ModelHandle& model, OH_AI_TensorHandleArray& inputs, OH_AI_TensorHandleArray& outputs);

    std::map<int32_t, OH_AI_ModelHandle> modelMap_ {};
    int32_t modelIdTag_ = 0;
    std::mutex mutex_;
    bool initFlag_ = false;
    OH_AI_ContextHandle context_ = nullptr;
};
} // namespace AIS
} // namespace OHOS

#endif // AI_SERVICE_IMPL_H